package com.elookinto.sample;

import com.sun.jersey.api.container.filter.UriConnegFilter;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.MediaType;

public class MediaTypeFilter extends UriConnegFilter {

    private static final Map<String, MediaType> MEDIA_TYPE_MAP = new HashMap<String, MediaType>(2);

    static {
        MEDIA_TYPE_MAP.put("json", MediaType.APPLICATION_JSON_TYPE);
        MEDIA_TYPE_MAP.put("xml", MediaType.APPLICATION_XML_TYPE);
        MEDIA_TYPE_MAP.put("txt", MediaType.TEXT_PLAIN_TYPE);
        MEDIA_TYPE_MAP.put("html", MediaType.TEXT_HTML_TYPE);
        MEDIA_TYPE_MAP.put("xhtml", MediaType.APPLICATION_XHTML_XML_TYPE);
        final MediaType jpeg = new MediaType("image", "jpeg");
        MEDIA_TYPE_MAP.put("jpg", jpeg);
        MEDIA_TYPE_MAP.put("jpeg", jpeg);
        MEDIA_TYPE_MAP.put("zip", new MediaType("application", "x-zip-compressed"));
    }

    public MediaTypeFilter() {
        super(MEDIA_TYPE_MAP);
    }
}
